package com.bluefish.bltuan.tools.annotation;

public final class StringUtil {
	
	private static final String[] STOPWORDS = {"，","。","？","！"," ","："," "};

	private StringUtil() {
		
	}
	
	public static boolean contains(String[] array, String target) {
		if(array == null || target == null)
			return false;
		for(String temp : array) {
			if(temp.equals(target)){
				return true;
			}
		}
		return false;
	
	}
	
	public static int getLastStop(String info, int endIndex){
		String value = info.substring(0 , endIndex);
		int stop = 0;
		for(String stopWord:STOPWORDS){
			int pos = value.lastIndexOf(stopWord);
			if(pos > stop)
				stop = pos;
		}
		return stop;
	}
	
	public static int getNextStop(String info, int startIndex){
		String value = info.substring(startIndex);
		int stop = value.length();
		for(String stopWord:STOPWORDS){
			int pos = value.indexOf(stopWord);
			if(pos != -1 && pos < stop)
				stop = pos;
		}
		return stop + startIndex;
	}
	
}
